home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODUtil / Include / FWFxMath.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  20.0 KB  |  652 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFxMath.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWFXMATH_H
  11. #define FWFXMATH_H
  12.  
  13. // ----- Foundation Includes -----
  14.  
  15. #ifndef FWSTDDEF_H
  16. #include "FWStdDef.h"
  17. #endif
  18.  
  19. // ----- OpenDoc Includes -----
  20.  
  21. #ifndef _ODMath_
  22. #include <ODMath.h>
  23. #endif
  24.  
  25. #if FW_LIB_EXPORT_PRAGMAS
  26. #pragma lib_export on
  27. #endif
  28.  
  29. //========================================================================================
  30. // Definitions and utilities
  31.  
  32. // These have to be done as macros because Metrowerks C++ 1.2.2 has difficulties
  33. //    with inlines that call other inlines
  34.  
  35. #define FW_PrivIntToFixed(i)            (ODFixed)((long) (i) << 16)
  36. #define FW_PrivDoubleToFixed(d)            (ODFixed)((double) (d) * 65536.0)
  37.  
  38. #define FW_PrivFixedToInt(f)            (int)((ODFixed)(f + 0x00008000) >> 16)
  39. #define FW_PrivFixedToTruncatedInt(f)    (int)((ODFixed)(f + 0x00000010) >> 16)
  40.  
  41. #define FW_PrivFixedToDouble(f)            (double)((ODFixed)(f) / 65536.0)
  42.  
  43. //========================================================================================
  44. // Forward class declaration
  45. //========================================================================================
  46.  
  47. class FW_CLASS_ATTR FW_CWide;
  48. class FW_CLASS_ATTR FW_CFixed;
  49. class FW_CLASS_ATTR FW_CWritableStream;
  50. class FW_CLASS_ATTR FW_CReadableStream;
  51.  
  52. //========================================================================================
  53. //    Global operators << and >>
  54. //========================================================================================
  55.  
  56. FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CFixed& fx);
  57. FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CFixed& fx);
  58.  
  59. //========================================================================================
  60. // CLASS FW_CFixed
  61. //========================================================================================
  62.  
  63. class FW_CLASS_ATTR FW_CFixed
  64. {
  65. public:
  66.     // ----- Construction/destruction -----
  67.     
  68.     friend inline FW_CFixed FW_IntToFixed(int i);
  69.     friend inline FW_CFixed FW_DoubleToFixed(double d);
  70.     friend inline FW_CFixed FW_ODFixedToFixed(ODFixed f);
  71.     
  72.     FW_CFixed();        // No defined value
  73.  
  74.     // ----- Copying -----
  75.  
  76. // Using the compiler generate ones makes the optimizer work better
  77. //    inline CFixed(const CFixed& f) : fRep(f.fRep) { }
  78. //    inline CFixed& operator=(const CFixed& f) { fRep = f.fRep; return *this; }
  79.  
  80.     // ----- Input/output
  81.  
  82.     friend FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CFixed& fx);
  83.     friend FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CFixed& fx);
  84.  
  85.     // ----- Assignment operators -----
  86.  
  87.     FW_CFixed&            SetInt(int i);
  88.     FW_CFixed&            SetDouble(double d);
  89.     FW_CFixed&            SetODFixed(ODFixed f);
  90.     
  91.     // ----- Converion operators -----
  92.     
  93.     int                    AsInt() const;
  94.     int                    AsTruncatedInt() const;
  95.     double                AsDouble() const;
  96.     ODFixed                AsODFixed() const;
  97.     
  98.     operator void*        () const    { return (void*) fRep; }
  99.         // This is only for convenience of testing against 0
  100.  
  101.     // ----- Arithmetic operators -----
  102.  
  103.     FW_CFixed            operator -    () const;
  104.     FW_CFixed            operator +    () const;
  105.     
  106.     FW_CFixed&            operator +=    (FW_CFixed fixed);
  107.     FW_CFixed&            operator -=    (FW_CFixed fixed);
  108.     FW_CFixed&            operator *=    (FW_CFixed fixed);
  109.     FW_CFixed&            operator /=    (FW_CFixed fixed);
  110.     
  111.     FW_CFixed            Half() const;
  112.     FW_CFixed            MultipliedByInt(int i) const;
  113.     FW_CFixed            DividedByInt(int i) const;
  114.     
  115.     FW_CFixed            RoundedToInt() const;
  116.     
  117.     friend FW_CWide FW_FUNC_ATTR  FW_WideMultiply    (FW_CFixed f1, FW_CFixed f2);
  118.     friend FW_CFixed FW_FUNC_ATTR operator / (const FW_CWide& w1, FW_CFixed f2);
  119.  
  120.     FW_CFixed&            operator ++    ();            // prefix
  121.     void                operator ++    (int i);    // postfix
  122.     FW_CFixed&            operator --    ();            // prefix
  123.     void                 operator --    (int i);    // postfix
  124.     
  125. #ifdef FW_DEBUG
  126.     friend    FW_FUNC_ATTR    FW_CFixed    operator +    (FW_CFixed f1, FW_CFixed f2);
  127.     friend    FW_FUNC_ATTR    FW_CFixed    operator -    (FW_CFixed f1, FW_CFixed f2);
  128.     friend    FW_FUNC_ATTR    FW_CFixed    operator *    (FW_CFixed f1, FW_CFixed f2);
  129.     friend    FW_FUNC_ATTR    FW_CFixed    operator /    (FW_CFixed f1, FW_CFixed f2);
  130. #else
  131.     friend    inline            FW_CFixed    operator +    (FW_CFixed f1, FW_CFixed f2);
  132.     friend    inline            FW_CFixed    operator -    (FW_CFixed f1, FW_CFixed f2);
  133.     friend    inline            FW_CFixed    operator *    (FW_CFixed f1, FW_CFixed f2);
  134.     friend    inline            FW_CFixed    operator /    (FW_CFixed f1, FW_CFixed f2);
  135. #endif
  136.  
  137.     // ----- Equality operators -----
  138.     
  139.     friend inline FW_Boolean    operator ==    (FW_CFixed f1, FW_CFixed f2);
  140.     friend inline FW_Boolean    operator !=    (FW_CFixed f1, FW_CFixed f2);
  141.     friend inline FW_Boolean    operator >    (FW_CFixed f1, FW_CFixed f2);
  142.     friend inline FW_Boolean    operator <    (FW_CFixed f1, FW_CFixed f2);
  143.     friend inline FW_Boolean    operator >=    (FW_CFixed f1, FW_CFixed f2);
  144.     friend inline FW_Boolean    operator <=    (FW_CFixed f1, FW_CFixed f2);
  145.  
  146.     // ----- Transcendental methods
  147.     
  148.     FW_CFixed            Sin() const;
  149.     FW_CFixed            Cos() const;
  150.     FW_CFixed            Sqrt() const;
  151.  
  152.     // ----- Implementation
  153. private:
  154.     ODFixed                fRep;
  155.  
  156.     FW_CFixed(ODFixed rep);
  157. };
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // FW_CFixed::FW_CFixed
  161. //----------------------------------------------------------------------------------------
  162.  
  163. inline FW_CFixed::FW_CFixed()
  164. {
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. // FW_CFixed::FW_CFixed
  169. //----------------------------------------------------------------------------------------
  170.  
  171. inline FW_CFixed::FW_CFixed(ODFixed rep) : fRep(rep)
  172. {
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // FW_IntToFixed
  177. //----------------------------------------------------------------------------------------
  178.  
  179. inline FW_CFixed FW_IntToFixed(int i)
  180. {
  181.     return FW_CFixed(FW_PrivIntToFixed(i));
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. // FW_DoubleToFixed
  186. //----------------------------------------------------------------------------------------
  187.  
  188. inline FW_CFixed FW_DoubleToFixed(double d)
  189. {
  190.     return FW_CFixed(FW_PrivDoubleToFixed(d));
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // FW_ODFixedToFixed
  195. //----------------------------------------------------------------------------------------
  196.  
  197. inline FW_CFixed FW_ODFixedToFixed(ODFixed f)
  198. {
  199.     return FW_CFixed(f);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // FW_CFixed::AsInt
  204. //----------------------------------------------------------------------------------------
  205.  
  206. inline int FW_CFixed::AsInt() const
  207. {
  208.     return FW_PrivFixedToInt(fRep);
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. // FW_CFixed::AsTruncatedInt
  213. //----------------------------------------------------------------------------------------
  214.  
  215. inline int FW_CFixed::AsTruncatedInt() const
  216. {
  217.     return FW_PrivFixedToTruncatedInt(fRep);
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. // FW_CFixed::AsDouble
  222. //----------------------------------------------------------------------------------------
  223.  
  224. inline double FW_CFixed::AsDouble() const
  225. {
  226.     return FW_PrivFixedToDouble(fRep);
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. // FW_CFixed::AsODFixed
  231. //----------------------------------------------------------------------------------------
  232.  
  233. inline ODFixed FW_CFixed::AsODFixed() const
  234. {
  235.     return fRep;
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. // FW_CFixed::SetInt
  240. //----------------------------------------------------------------------------------------
  241.  
  242. inline FW_CFixed& FW_CFixed::SetInt(int i)
  243. {
  244.     fRep = FW_PrivIntToFixed(i);
  245.     return *this;
  246. }
  247.     
  248. //----------------------------------------------------------------------------------------
  249. // FW_CFixed::SetDouble
  250. //----------------------------------------------------------------------------------------
  251.  
  252. inline FW_CFixed& FW_CFixed::SetDouble(double d)
  253. {
  254.     fRep = FW_PrivDoubleToFixed(d);
  255.     return *this;
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. // FW_CFixed::SetODFixed
  260. //----------------------------------------------------------------------------------------
  261.  
  262. inline FW_CFixed& FW_CFixed::SetODFixed(ODFixed f)
  263. {
  264.     fRep = f;
  265.     return *this;
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. // FW_CFixed::operator-
  270. //----------------------------------------------------------------------------------------
  271.  
  272. inline FW_CFixed FW_CFixed::operator-() const
  273. {
  274.     return FW_CFixed(-fRep);
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. // FW_CFixed::operator+
  279. //----------------------------------------------------------------------------------------
  280.  
  281. inline FW_CFixed FW_CFixed::operator+() const
  282. {
  283.     return *this;
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // FW_CFixed::operator+=
  288. //----------------------------------------------------------------------------------------
  289.  
  290. inline FW_CFixed& FW_CFixed::operator+=(FW_CFixed fixed)
  291. {
  292.     fRep += fixed.fRep;
  293.     return *this;
  294. }
  295.  
  296. //----------------------------------------------------------------------------------------
  297. // FW_CFixed::operator-=
  298. //----------------------------------------------------------------------------------------
  299.  
  300. inline FW_CFixed& FW_CFixed::operator-=(FW_CFixed fixed)
  301. {
  302.     fRep -= fixed.fRep;
  303.     return *this;
  304. }
  305.  
  306. //----------------------------------------------------------------------------------------
  307. // FW_CFixed::operator*=
  308. //----------------------------------------------------------------------------------------
  309.  
  310. inline FW_CFixed& FW_CFixed::operator*=(FW_CFixed fixed)
  311. {
  312.     fRep = ODFixedMultiply(fRep, fixed.fRep);
  313.     return *this;
  314. }
  315.  
  316. //----------------------------------------------------------------------------------------
  317. // FW_CFixed::operator/=
  318. //----------------------------------------------------------------------------------------
  319.  
  320. inline FW_CFixed& FW_CFixed::operator/=(FW_CFixed fixed)
  321. {
  322.     fRep = ODFixedDivide(fRep, fixed.fRep);
  323.     return *this;
  324. }
  325.  
  326. //----------------------------------------------------------------------------------------
  327. // FW_CFixed::Half
  328. //----------------------------------------------------------------------------------------
  329.  
  330. inline FW_CFixed FW_CFixed::Half() const
  331. {
  332.     return FW_CFixed(fRep / 2);
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. // FW_CFixed::MultipliedByInt
  337. //----------------------------------------------------------------------------------------
  338.  
  339. inline FW_CFixed FW_CFixed::MultipliedByInt(int i) const
  340. {
  341.     return FW_CFixed(fRep * i);
  342. }
  343.  
  344. //----------------------------------------------------------------------------------------
  345. // FW_CFixed::DividedByInt
  346. //----------------------------------------------------------------------------------------
  347.  
  348. inline FW_CFixed FW_CFixed::DividedByInt(int i) const
  349. {
  350.     return FW_CFixed(fRep / i);
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. // FW_CFixed::RoundedToInt
  355. //----------------------------------------------------------------------------------------
  356.  
  357. inline FW_CFixed FW_CFixed::RoundedToInt() const
  358. {
  359.     return FW_CFixed((fRep + 0x00008000) & 0xFFFF0000ul);
  360. }
  361.  
  362. //----------------------------------------------------------------------------------------
  363. // FW_CFixed::operator++
  364. //----------------------------------------------------------------------------------------
  365.  
  366. inline FW_CFixed& FW_CFixed::operator++()                        // prefix
  367. {
  368.     fRep += FW_PrivIntToFixed(1);
  369.     return *this;
  370. }
  371.  
  372. //----------------------------------------------------------------------------------------
  373. // FW_CFixed::operator++
  374. //----------------------------------------------------------------------------------------
  375.  
  376. inline void FW_CFixed::operator++(int /* i */)    // postfix
  377. {
  378.     fRep += FW_PrivIntToFixed(1);
  379. }
  380.  
  381. //----------------------------------------------------------------------------------------
  382. // FW_CFixed::operator--
  383. //----------------------------------------------------------------------------------------
  384.  
  385. inline FW_CFixed& FW_CFixed::operator--()                // prefix
  386. {
  387.     fRep -= FW_PrivIntToFixed(1);
  388.     return *this;
  389. }
  390.  
  391. //----------------------------------------------------------------------------------------
  392. // FW_CFixed::operator--
  393. //----------------------------------------------------------------------------------------
  394.  
  395. inline void FW_CFixed::operator--(int /* i */)    // postfix
  396. {
  397.     fRep -= FW_PrivIntToFixed(1);
  398. }
  399.  
  400. //========================================================================================
  401. // Global functions
  402. //========================================================================================
  403.  
  404. #ifndef FW_DEBUG
  405.  
  406. inline FW_CFixed operator+(FW_CFixed f1, FW_CFixed f2)
  407. {
  408.     return FW_CFixed(f1.fRep + f2.fRep);
  409. }
  410.  
  411. inline FW_CFixed operator-(FW_CFixed f1, FW_CFixed f2)
  412. {
  413.     return FW_CFixed(f1.fRep - f2.fRep);
  414. }
  415.  
  416. inline FW_CFixed operator*(FW_CFixed f1, FW_CFixed f2)
  417. {
  418.     return FW_CFixed(ODFixedMultiply(f1.fRep, f2.fRep));
  419. }
  420.  
  421. inline FW_CFixed operator/(FW_CFixed f1, FW_CFixed f2)
  422. {
  423.     return FW_CFixed(ODFixedDivide(f1.fRep, f2.fRep));
  424. }
  425.  
  426. #endif
  427.  
  428. inline FW_Boolean operator>(FW_CFixed f1, FW_CFixed f2)
  429. {
  430.     return f1.fRep > f2.fRep;
  431. }
  432.  
  433. inline FW_Boolean operator==(FW_CFixed f1, FW_CFixed f2)
  434. {
  435.     return f1.fRep == f2.fRep;
  436. }
  437.  
  438. inline FW_Boolean operator<(FW_CFixed f1, FW_CFixed f2)
  439. {
  440.     return f1.fRep < f2.fRep;
  441. }
  442.  
  443. inline FW_Boolean operator>=(FW_CFixed f1, FW_CFixed f2)
  444. {
  445.     return f1.fRep >= f2.fRep;
  446. }
  447.  
  448. inline FW_Boolean operator!=(FW_CFixed f1, FW_CFixed f2)
  449. {
  450.     return f1.fRep != f2.fRep;
  451. }
  452.  
  453. inline FW_Boolean operator<=(FW_CFixed f1, FW_CFixed f2)
  454. {
  455.     return f1.fRep <= f2.fRep;
  456. }
  457.  
  458. //========================================================================================
  459. // CLASS FW_CWide
  460. //========================================================================================
  461.  
  462. class FW_CLASS_ATTR FW_CWide
  463. {
  464. public:
  465.     // ----- Construction
  466.     friend FW_CWide    FW_FUNC_ATTR    FW_IntToWide(int i);
  467.     friend FW_CWide    FW_FUNC_ATTR    FW_ODFixedToWide(ODFixed f);
  468.  
  469.                         FW_CWide(FW_CFixed f);
  470.                         
  471.     // ----- Conversion
  472.     int                    AsInt() const;
  473.     ODFixed                AsODFixed() const;
  474.  
  475.     operator             FW_CFixed() const;
  476.  
  477.     // ----- Arithmetic operators -----
  478.  
  479.     FW_CWide&            operator +=    (const FW_CWide& w);
  480.     FW_CWide&            operator -=    (const FW_CWide& w);
  481.     
  482.     friend FW_CWide     FW_FUNC_ATTR    operator +    (const FW_CWide& w1, const FW_CWide& w2);
  483.     friend FW_CWide     FW_FUNC_ATTR    operator -    (const FW_CWide& w1, const FW_CWide& w2);
  484.     friend FW_CWide     FW_FUNC_ATTR    FW_WideMultiply    (FW_CFixed f1, FW_CFixed f2);
  485.     friend FW_CFixed FW_FUNC_ATTR    operator /    (const FW_CWide& w1, FW_CFixed f2);
  486.  
  487.     // ----- Equality operators -----
  488.     
  489.     friend inline FW_Boolean    operator ==    (const FW_CWide& w1, const FW_CWide& w2);
  490.     friend inline FW_Boolean    operator !=    (const FW_CWide& w1, const FW_CWide& w2);
  491.     friend inline FW_Boolean    operator >    (const FW_CWide& w1, const FW_CWide& w2);
  492.     friend inline FW_Boolean    operator <    (const FW_CWide& w1, const FW_CWide& w2);
  493.     friend inline FW_Boolean    operator >=    (const FW_CWide& w1, const FW_CWide& w2);
  494.     friend inline FW_Boolean    operator <=    (const FW_CWide& w1, const FW_CWide& w2);
  495.  
  496.     // ----- Transcendental methods
  497.  
  498.     FW_CFixed            Sqrt() const;
  499.  
  500.     // ------ Implementation
  501. private:
  502.     ODWide                fRep;
  503.     
  504.                         FW_CWide(const ODWide& w);
  505.                         FW_CWide(long hi, unsigned long lo);
  506. };
  507.  
  508. //----------------------------------------------------------------------------------------
  509. //    FW_CWide::FW_CWide
  510. //----------------------------------------------------------------------------------------
  511.  
  512. inline FW_CWide::FW_CWide(const ODWide& w) :
  513.     fRep(w)
  514. {
  515. }
  516.  
  517. //----------------------------------------------------------------------------------------
  518. //    FW_CWide::FW_CWide
  519. //----------------------------------------------------------------------------------------
  520.  
  521. inline FW_CWide::FW_CWide(long hi, unsigned long lo)
  522. {
  523.     fRep.hi = hi, fRep.lo = lo;
  524. }
  525.  
  526. //----------------------------------------------------------------------------------------
  527. //    FW_CWide::FW_CWide
  528. //----------------------------------------------------------------------------------------
  529.  
  530. inline FW_CWide& FW_CWide::operator +=    (const FW_CWide& w)
  531. {
  532.     ODWideAdd(&fRep, &w.fRep);
  533.     return *this;
  534. }
  535.  
  536. //----------------------------------------------------------------------------------------
  537. //    FW_CWide::FW_CWide
  538. //----------------------------------------------------------------------------------------
  539.  
  540. inline FW_CWide& FW_CWide::operator -=    (const FW_CWide& w)
  541. {
  542.     ODWideSubtract(&fRep, &w.fRep);
  543.     return *this;
  544. }
  545.  
  546. //----------------------------------------------------------------------------------------
  547. //    operator ==
  548. //----------------------------------------------------------------------------------------
  549.  
  550. inline FW_Boolean operator ==    (const FW_CWide& w1, const FW_CWide& w2)
  551. {
  552.     return ODWideCompare(&w1.fRep, &w2.fRep) == 0;
  553. }
  554.  
  555. //----------------------------------------------------------------------------------------
  556. //    operator ==
  557. //----------------------------------------------------------------------------------------
  558.  
  559. inline FW_Boolean operator !=    (const FW_CWide& w1, const FW_CWide& w2)
  560. {
  561.     return ODWideCompare(&w1.fRep, &w2.fRep) != 0;
  562. }
  563.  
  564. //----------------------------------------------------------------------------------------
  565. //    operator ==
  566. //----------------------------------------------------------------------------------------
  567.  
  568. inline FW_Boolean operator >    (const FW_CWide& w1, const FW_CWide& w2)
  569. {
  570.     return ODWideCompare(&w1.fRep, &w2.fRep) > 0;
  571. }
  572.  
  573. //----------------------------------------------------------------------------------------
  574. //    operator ==
  575. //----------------------------------------------------------------------------------------
  576.  
  577. inline FW_Boolean operator <    (const FW_CWide& w1, const FW_CWide& w2)
  578. {
  579.     return ODWideCompare(&w1.fRep, &w2.fRep) < 0;
  580. }
  581.  
  582. //----------------------------------------------------------------------------------------
  583. //    operator ==
  584. //----------------------------------------------------------------------------------------
  585.  
  586. inline FW_Boolean operator >=    (const FW_CWide& w1, const FW_CWide& w2)
  587. {
  588.     return ODWideCompare(&w1.fRep, &w2.fRep) >= 0;
  589. }
  590.  
  591. //----------------------------------------------------------------------------------------
  592. //    operator ==
  593. //----------------------------------------------------------------------------------------
  594.  
  595. inline FW_Boolean operator <=    (const FW_CWide& w1, const FW_CWide& w2)
  596. {
  597.     return ODWideCompare(&w1.fRep, &w2.fRep) <= 0;
  598. }
  599.  
  600. //========================================================================================
  601. // Global utilities
  602. //========================================================================================
  603.  
  604. //----------------------------------------------------------------------------------------
  605. //    FW_CFixed
  606. //----------------------------------------------------------------------------------------
  607.  
  608. inline FW_CFixed FW_Minimum(FW_CFixed f1, FW_CFixed f2)
  609. {
  610.     return f1 < f2 ? f1 : f2;
  611. }
  612.  
  613. inline FW_CFixed FW_Maximum(FW_CFixed f1, FW_CFixed f2)
  614. {
  615.     return f1 > f2 ? f1 : f2;
  616. }
  617.  
  618. inline FW_CFixed FW_Abosolute(FW_CFixed f)
  619. {
  620.     return f > FW_IntToFixed(0) ? f : -f;
  621. }
  622.  
  623. //----------------------------------------------------------------------------------------
  624. //    FW_CWide
  625. //----------------------------------------------------------------------------------------
  626.  
  627. inline FW_CWide FW_Minimum(const FW_CWide& w1, const FW_CWide& w2)
  628. {
  629.     return w1 < w2 ? w1 : w2;
  630. }
  631.  
  632. inline FW_CWide FW_Maximum(const FW_CWide& w1, const FW_CWide& w2)
  633. {
  634.     return w1 > w2 ? w1 : w2;
  635. }
  636.  
  637. //========================================================================================
  638. // Global constants
  639. //========================================================================================
  640.  
  641. extern const FW_CFixed FW_kFixed0;        // 0
  642. extern const FW_CFixed FW_kFixedPos1;    // +1
  643. extern const FW_CFixed FW_kFixedNeg1;    // -1
  644. extern const FW_CFixed FW_kFixed72;        // 72
  645. extern const FW_CFixed FW_kFixedPI;        // pi
  646.  
  647. #if FW_LIB_EXPORT_PRAGMAS
  648. #pragma lib_export off
  649. #endif
  650.  
  651. #endif
  652.